package com.per.mybootall.jdk8Stream.Function;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.function.Function;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/2/22
 * Time: 15:21
 * Description:
 */
@Component
@EnableScheduling
public class TestFunction {
    @Scheduled(cron = "0/10 * * * * ?")
    public void test() {
        UseFunction01 useFun01=new UseFunction01();
        UseFunction02 useFun02=new UseFunction02();
        System.out.println("函数式编程开始计算====》》》》》");
        Integer multipRes= useFun01.multiplicationFun(3,p->{
          return Integer.valueOf(p.toString())*Integer.valueOf(p.toString());
        });
        System.out.println("函数1「乘」执行结果为："+multipRes);
        Integer addRes=useFun02.addFun(2,p->{
            return Integer.valueOf(p.toString())+1;
        });
        System.out.println("函数2「加」执行结果为："+addRes);


        Function<Integer, Integer> plus = i -> {return i + 1;};
        Function<Integer, Integer> mult = i -> {return i * i;};

       Integer res= plus.andThen(mult).apply(1);
       System.out.println("自执行函数1结果："+res);
       Integer res2=plus.compose(mult).apply(2);
       System.out.println("自执行函数2结果："+res2);
    }
}
